package com.pipe.protocol.events.table;

import com.pipe.util.IntegerConveter;
import io.netty.buffer.ByteBuf;

/**
 * @author Kiven
 */
public class TableMapEventPostHeader {

    /**
     * If the table id is 0x00ffffff it is a dummy event that
     * should have the end of statement flag set that declares
     * that all table maps can be freed. Otherwise it refers to
     * a table defined by TABLE_MAP_EVENT.
     */
    private long tableId;
    private int flags;

    public TableMapEventPostHeader(long tableId, int flags) {
        this.tableId = tableId;
        this.flags = flags;
    }

    public static TableMapEventPostHeader build(ByteBuf byteBuf){
        byte[] tableId = new byte[6];
        byteBuf.readBytes(tableId);
        long ti = IntegerConveter.getLongFromByte(tableId);
        int f = byteBuf.readUnsignedShortLE();
        return new TableMapEventPostHeader(ti, f);
    }

    @Override
    public String toString() {
        return "TableMapEventPostHeader{" +
                "tableId=" + tableId +
                ", flags=" + flags +
                '}';
    }
}